﻿using System;
using System.Windows.Input;

namespace Epon.EponEl5600.Command
{
    public abstract class Command : ICommand
    {

        public event EventHandler CanExecuteChanged;

        protected readonly Action<object> MExecute;
        protected readonly Predicate<object> MCanExecute;

        protected Command(Action<object> execute)
            : this(execute, null)
        {

        }

        protected Command(Action<object> execute, Predicate<object> canExecute)
        {
            if (execute == null)
                throw new ArgumentNullException("execute");
            MExecute = execute;
            MCanExecute = canExecute;
        }

        public virtual bool CanExecute(object parameter)
        {
            return MCanExecute == null ? true : MCanExecute(parameter);
        }

        public virtual void Execute(object parameter)
        {
            MExecute(parameter);
        }

        public virtual void RaiseCanExecuteChanged(EventArgs eventArgs)
        {
            if (CanExecuteChanged != null)
            {
                CanExecuteChanged(this, eventArgs);
            }
        }
    }
}
